*NOTE: fill in root directory where all files are located or this will error out!
cd ""

log using "analysis.log", replace

****MANUSCRIPT*****
*TABLE 1
use "study2_prepped.dta", clear
reg ppl anger1 fear1
vif
reg ppl anger2 fear2
vif

*FIGURE3

use "study1_prepped.dta", clear
ci2 anger fear, corr
ci2 anger2 fear2, corr
ci2 anger3 fear3, corr

use "study2_prepped.dta", clear
ci2 anger fear, corr
ci2 anger1 fear1, corr
ci2 anger2 fear2, corr

*Graph produced manually in excel

*Table 2 is in Mplus

*Table 3

use "study2_prepped.dta", clear
drop anger fear
gen anger = .
replace anger = anger1 if panasv == 1
replace anger = anger2 if panasv == 2

gen fear = .
replace fear = fear1 if panasv == 1
replace fear = fear2 if panasv == 2

gen angfeardiff = anger-fear

label define panasv 1 "Standard" 2 "Modified"
label value panasv panasv

label define treat 0 "Control" 1 "Anger" 2 "Fear" 
label value treat treat

by treat, sort: ttest angfeardiff, by(panasv) unequal

****APPENDIX****

*Runs the balance stats for everything

*TABLE A1
*Study1 
use "study1_prepped.dta", clear
sem (FEAR -> afraid anxious) (ANGER ->angry hostile) (NEGAFF-> ashamed upset distressed), /*
*/ var(FEAR@1 ANGER@1 NEGAFF@1) cov(e.angry*e.upset) cov(e.ashamed*e.angry) cov(e.hostile*e.ashamed) cov(e.afraid*e.ashamed) method(mlmv) standardized

*Study2
use "study2_prepped.dta", clear
sem (FEAR -> afraid anxious) (ANGER ->angry hostile) (NEGAFF-> upset distressed disturbed), /*
*/ var(FEAR@1 ANGER@1 NEGAFF@1) cov(e.upset*e.disturbed) cov(e.anxious*e.distressed) method(mlmv) standardized

*FIGURE A2
use "study2_prepped.dta", clear
reg anger i.treat##i.panasv
margins, at(treat=(0 1 2) panasv = (1 2))
marginsplot, recast(scatter)

reg fear i.treat##i.panasv
margins, at(treat=(0 1 2) panasv = (1 2))
marginsplot, recast(scatter)

*A3: correlations of anger/fear and populism

by panasv, sort: pwcorr ppl anger fear

*A4: Balance statistics
*STUDY 1
use "study1_prepped.dta", clear

gen region =.
replace region = 1 if state == 1
replace region = 6 if state == 2
replace region = 5 if state == 3
replace region = 1 if state == 4
replace region = 4 if state == 5
replace region = 4 if state == 6
replace region = 2 if state == 7
replace region = 2 if state == 8
replace region = 2 if state == 9
replace region = 1 if state == 10
replace region = 1 if state == 11
replace region = 6 if state == 12
replace region = 4 if state == 13
replace region = 3 if state == 14
replace region = 3 if state == 15
replace region = 3 if state == 16
replace region = 3 if state == 17
replace region = 1 if state == 18
replace region = 1 if state == 19
replace region = 2 if state == 20
replace region = 2 if state == 21
replace region = 2 if state == 22
replace region = 3 if state == 23
replace region = 3 if state == 24
replace region = 1 if state == 25
replace region = 3 if state == 26
replace region = 4 if state == 27
replace region = 3 if state == 28
replace region = 4 if state == 29
replace region = 2 if state == 30
replace region = 2 if state == 31
replace region = 5 if state == 32
replace region = 2 if state == 33
replace region = 1 if state == 34
replace region = 3 if state == 35
replace region = 3 if state == 36
replace region = 3 if state == 37
replace region = 3 if state == 38
replace region = 2 if state == 39
replace region = 6 if state == 40
replace region = 2 if state == 41
replace region = 1 if state == 42
replace region = 3 if state == 43
replace region = 1 if state == 44
replace region = 5 if state == 45
replace region = 4 if state == 46
replace region = 2 if state == 47
replace region = 1 if state == 48
replace region = 1 if state == 49
replace region = 1 if state == 50
replace region = 3 if state == 51
replace region = 4 if state == 52

label define regionlab 1 "Southeast" 2 "Northeast" 3 "Midwest" 4 "West" 5 "Southwest" 6 "Non-continental US"
label variable region regionlab 

replace age = 2018 - age

tab gender treat, chi column taub
tab region treat, chi column taub
reg ideology i.treat
margins treat
reg ed i.treat
margins treat
reg income i.treat
margins treat
reg age i.treat
margins treat

*STUDY2
use "study2_prepped.dta", clear

label define regionlab 1 "Southeast" 2 "Northeast" 3 "Midwest" 4 "West" 5 "Southwest" 6 "Non-continental US"
label variable region regionlab 

sum age

tab gender treat, chi column taub
tab region treat, chi column taub
reg ideology i.treat
margins treat
reg ed i.treat
margins treat
reg income i.treat
margins treat
reg age i.treat
margins treat

log close
